package com.example.fasttask;

import android.content.Context;
import android.database.sqlite.SQLiteDatabase;
import android.database.sqlite.SQLiteOpenHelper;
import android.util.Log;

public class TaskSQLiteHelper extends SQLiteOpenHelper {
	
	public static final String TABLE_TASKS = "tasks";
	public static final String COLUMN_ID = "id";
	public static final String COLUMN_TASK = "taskname";
	public static final String COLUMN_DATE = "date";//should be a string
	public static final String COLUMN_RECUR = "recurring"; // integer 0 or 1
	public static final String COLUMN_LENGTH = "length";

	private static final String DATABASE_NAME = "tasks.db";
	private static final int DATABASE_VERSION = 6;
	
	private static final String DATABASE_CREATE = "create table "
			+ TABLE_TASKS + "(" + COLUMN_ID
			+ " integer primary key autoincrement, " + COLUMN_TASK
			+ " text not null, "+ COLUMN_DATE
			+ " text not null, "+ COLUMN_RECUR
			+ " integer not null, "+ COLUMN_LENGTH // should  create another column?
			+ " integer not null"+ ");";
	
	public TaskSQLiteHelper(Context context) {
		super(context, DATABASE_NAME, null, DATABASE_VERSION);
	}
	
	@Override
	public void onCreate(SQLiteDatabase database) {
		database.execSQL(DATABASE_CREATE);
	}
	
	@Override
	public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
		Log.w(TaskSQLiteHelper.class.getName(),
				"Upgrading database from version " + oldVersion + " to "
						+ newVersion + ", which will destroy all old data");
		db.execSQL("DROP TABLE IF EXISTS " + TABLE_TASKS);
		onCreate(db);
	}
}
